﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Scryber.Components;

namespace Scryber.Testing.AllSystemTests
{
    public class CustomAssigments
    {


        public void AddItemAssigments(PDFItemCollection toitems)
        {
            toitems.Add("MyCustomBitmap", _itemBitmap);
            toitems.Add("MyCustomContent", GetPlaceHolderContent());
            toitems.Add("MyXPathContent", CustomBindings.GetByLastNameStatic("Dickens"));
        }


        public void ApplyCustomActions(Scryber.Components.PDFDocument doc)
        {
            PDFImage img = doc.FindAComponentById("MyDirectAssigment") as Scryber.Components.PDFImage;
            if (null != img)
                img.Data = _assignedBitmap;

            Scryber.Components.PDFPlaceHolder plac;
            if (doc.TryFindAComponentByID("CodedParsableContentPlaceHolder", out plac))
                plac.ParsableContents = GetPlaceHolderContent();


            if (doc.TryFindAComponentByID("CodedContentPlaceHolder", out plac))
                this.AddComponentsToPlaceHolder(plac);

            if (doc.TryFindAComponentByID("PageLevelPlaceHolder", out plac))
                this.AddPagesToPlaceHolder(plac);

            if (doc.TryFindAComponentByID("ComplexPlaceHolder", out plac))
                plac.ParsableContents = GetComplexPlaceHolderContent();
        }

        private static Scryber.Drawing.PDFImageData _itemBitmap = CustomImageFactory.GetCustomBitmap("DYNAMIC ITEM IMAGE", "MyCustomItemImageKey");
        private static Scryber.Drawing.PDFImageData _assignedBitmap = CustomImageFactory.GetCustomBitmap("DYNAMIC ASSIGNED IMAGE", "MyCustomAssignedImageKey");

        private string GetPlaceHolderContent()
        {
            string full = "<pdf:I>This is some <pdf:B>inline content</pdf:B> that has been assigned to the item collection from code behind</pdf:I>. ";
            return full;
        }

        private string GetComplexPlaceHolderContent()
        {
            string full = "<pdf:Div style:class='ph-padded ph-coloured' >" +
                "<pdf:Image src='./images/scryber_logo_380.png' style:width='100pt' />" +
                "<pdf:I>This is some <pdf:B>complex content</pdf:B> that has been assigned to the contents of the placeholder</pdf:I>." + 
                "</pdf:Div>";
            return full;
        }

        private void AddComponentsToPlaceHolder(PDFPlaceHolder plac)
        {
            PDFLabel lbl = new PDFLabel() { Text = "This is some text in a lablel.", FontBold = true };
            PDFLabel lbl2 = new PDFLabel() { Text = "This is some more text in a label. ", FontItalic = true };
            plac.Contents.Add(lbl);
            plac.Contents.Add(lbl2);
        }

        private void AddPagesToPlaceHolder(PDFPlaceHolder plac)
        {
            PDFPage page = new PDFPage() { OutlineTitle = "Placeholder page" };
            PDFDiv div = new PDFDiv() { StyleClass = "wide" };
            PDFLabel lbl = new PDFLabel() { Text = "This label has been added to a dynamically created page, and then included in the document via a PlaceHolder which still inherits all the styles", FontSize = 24 };
            plac.Contents.Add(page);
            page.Contents.Add(div);
            div.Contents.Add(lbl);
        }
        
    }


    
}
